//
//  Extension_TQRecord.swift
//  TQMedia
//
//  Created by XieLB on 2018/9/21.
//  Copyright © 2018年 CocoaPods. All rights reserved.
//

import CTMediator

// 模块名称
let TQMediaModuleRecordName = "TuQiangMedia"
// 子模块名称（录音）
let TQRecordModuleName = "TQRecord"
// 播放本地录音接口(项目本身资源)
let TQRecordPlayLocalRecord = "playLocalRecord"
// 播放录音接口
let TQRecordPlayRecord = "playRecord"
// 停止播放接口
let TQRecordStopRecord = "stopRecord"
// 获取开始播放闭包接口
let TQGetPlayRecordCloser = "getPlayRecordCloser"
// 获取停止播放闭包接口
let TQGetStopRecordCloser = "getStopRecordCloser"
// 下载状态变化触发闭包
let TQDownloadStateChangeCloser = "downloadStateChangeCloser"


public extension CTMediator {
    
    /// 播放本地录音接口(项目本身资源)
    ///
    /// - Parameter soundName: 录音路径
    func tq_playLocalRecord(soundName: String) {
        let params = [
            kCTMediatorParamsKeySwiftTargetModuleName: TQMediaModuleRecordName,
            "soundName": soundName
        ]
        performTarget(TQRecordModuleName, action: TQRecordPlayLocalRecord, params: params, shouldCacheTarget: true)
    }
    
    /// 播放录音接口
    ///
    /// - Parameter fname: 录音路径
    func tq_playRecord(fname: String, downloadUrl: String) {
        let params = [
            kCTMediatorParamsKeySwiftTargetModuleName: TQMediaModuleRecordName,
            "fname": fname,
            "downloadUrl": downloadUrl
        ]
        performTarget(TQRecordModuleName, action: TQRecordPlayRecord, params: params, shouldCacheTarget: true)
    }
    
    /// 停止播放接口
    ///
    /// - Parameter fname: 录音路径
    func tq_stopRecord(filePath: String) {
        let params = [
            kCTMediatorParamsKeySwiftTargetModuleName: TQMediaModuleRecordName,
            "fname": filePath
        ]
        performTarget(TQRecordModuleName, action: TQRecordStopRecord, params: params, shouldCacheTarget: false)
    }
    
    /// 开始播放触发闭包
    func tq_getPlayRecordCloser(closer: @escaping (() -> Void)) {
        let params = [
            kCTMediatorParamsKeySwiftTargetModuleName: TQMediaModuleRecordName,
            "closer": closer
            ] as [String : Any]
        performTarget(TQRecordModuleName, action: TQGetPlayRecordCloser, params: params, shouldCacheTarget: false)
    }
    
    /// 停止播放触发闭包
    func tq_getStopRecordCloser(closer: @escaping (() -> Void)) {
        let params = [
            kCTMediatorParamsKeySwiftTargetModuleName: TQMediaModuleRecordName,
            "closer": closer
            ] as [String : Any]
        performTarget(TQRecordModuleName, action: TQGetStopRecordCloser, params: params, shouldCacheTarget: false)
    }
    
    /// 下载状态变化触发闭包(下载状态 1：暂停、2：下载中、3：完成)
    func tq_downloadStateChangeCloser(closer: @escaping ((Int) -> Void)) {
        let params = [
            kCTMediatorParamsKeySwiftTargetModuleName: TQMediaModuleRecordName,
            "closer": closer
            ] as [String : Any]
        performTarget(TQRecordModuleName, action: TQDownloadStateChangeCloser, params: params, shouldCacheTarget: false)
    }
}
